package Chapter04.TS;
import java.util.ArrayList;
import java.util.Scanner;



public class MovieManagementSystem {
    //写一个关于

            private ArrayList<Movie> movieList;

            public MovieManagementSystem() {
                movieList = new ArrayList<Movie>();
            }

            public void addMovie(Movie movie) {
                movieList.add(movie);
            }

            public void removeMovie(Movie movie) {
                movieList.remove(movie);
            }

            public void displayMovies() {
                for (Movie movie : movieList) {
                    System.out.println(movie);
                }
            }

            public static void main(String[] args) {
                Scanner scanner = new Scanner(System.in);
                MovieManagementSystem system = new MovieManagementSystem();

                while (true) {
                    System.out.println("1. Add movie");
                    System.out.println("2. Remove movie");
                    System.out.println("3. Display movies");
                    System.out.println("4. Exit");
                    System.out.print("Enter your choice: ");

                    int choice = scanner.nextInt();

                    switch (choice) {
                        case 1:
                            System.out.print("Enter movie title: ");
                            String title = scanner.next();
                            System.out.print("Enter movie director: ");
                            String director = scanner.next();
                            System.out.print("Enter movie release year: ");
                            int releaseYear = scanner.nextInt();
                            Movie movie = new Movie(title, director, releaseYear);
                            system.addMovie(movie);
                            System.out.println("Movie added successfully.");
                            break;
                        case 2:
                            System.out.print("Enter movie title: ");
                            title = scanner.next();
                            System.out.print("Enter movie director: ");
                            director = scanner.next();
                            System.out.print("Enter movie release year: ");
                            releaseYear = scanner.nextInt();
                            movie = new Movie(title, director, releaseYear);
                            system.removeMovie(movie);
                            System.out.println("Movie removed successfully.");
                            break;
                        case 3:
                            system.displayMovies();
                            break;
                        case 4:
                            System.exit(0);
                        default:
                            System.out.println("Invalid choice. Please try again.");
                    }
                }
            }
        }

        class Movie {
            private String title;
            private String director;
            private int releaseYear;

            public Movie(String title, String director, int releaseYear) {
                this.title = title;
                this.director = director;
                this.releaseYear = releaseYear;
            }

            public String getTitle() {
                return title;
            }

            public String getDirector() {
                return director;
            }

            public int getReleaseYear() {
                return releaseYear;
            }

            public String toString() {
                return "Title: " + title + ", Director: " + director + ", Release Year: " + releaseYear;
            }
        }







